********************************************************************************
********************************************************************************
* Title: 		mht
* Project:		Stress, Ethnicity, and Prosocial Behavior
* Author:		Moritz Poll (moritz.poll@brown.edu)
* PIs:			Johannes Haushofer, Sara Lowes, Abednego Musau, David Ndetei, 
*				Nathan Nunn, Moritz Poll, Nancy Qian
* Purpose:		Adjusts results for multiple hypothesis testing
********************************************************************************
********************************************************************************

capture ssc install mhtreg
set seed 1234
global mht_bootstrap = 10000

local general_notes "Standard errors clustered at the participant level are reported in parentheses. Significance is denoted by \sym{*} \(p<0.1\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\)."
local notesspec1 "\textit{Notes}: $^a$ The average hydrocortisone effect is calculated as in equation~\eqref{eqn: Calculated Hydro Effect}. $^b$ The average coethnicity effect is calculated as in equation~\eqref{eqn: Calculated Coethnity Effect}. $^c$ The interaction effect is given by $\hat{\beta}_3$ in equation~\eqref{eqn: Main Specification}. All terms are described in the text. In this specification, we control for the interaction of a same-gender and same-age group indicator with hydrocortisone as well as gender, age group and ethnicity fixed effects of both players."
local cyd_note "The sample mean and standard deviation for the choose your dictator game refer to the share of decisions in which an in-group member was chosen among the decisions where one was available."
local social_proximity_note "Social proximity refers to the average measures of likelihood to be friends, trust and closeness rescaled to lie between 0 and 1."

eststo clear
foreach game in $main_table_vars {
	n dis "Correcting within `game'"
	use "$cleandata_dir/HIO_for_analysis_xlong.dta", clear

	keep if game_str == "`game'"
	
	preserve
	if "`game'" == "cyd" keep if game == 2 & cyd_owneth_available
	sum treatment
	global share_hydro = r(mean)
	sum _same_eth
	global share_same_eth = r(mean)
	sum _same_sex
	global share_same_sex = r(mean)
	sum _same_age
	global share_same_age = r(mean)
	restore

	gen composite1 = treatment * _same_eth - $share_hydro    * _same_eth ///
										   - $share_same_eth * treatment
	gen composite2 = treatment * _same_sex - $share_same_sex * treatment
	gen composite3 = treatment * _same_age - $share_same_age * treatment

if "`game'" == "cyd" {
	replace composite1 = -composite1 if game == 3
	replace composite2 = -composite2 if game == 3
	replace composite3 = -composite3 if game == 3
	bysort idround: egen cyd_diffcomposite1 = sum(composite1)
	bysort idround: egen cyd_diffcomposite2 = sum(composite2)
	bysort idround: egen cyd_diffcomposite3 = sum(composite3)
	replace cyd_diffcomposite1 = . if game == 3
	replace cyd_diffcomposite2 = . if game == 3
	replace cyd_diffcomposite3 = . if game == 3
	local v _same_eth  _same_sex  _same_age  $cyd_controls composite1 composite2 composite3
	
	foreach var in `v' {
		capture rename `var' `var'0
		rename cyd_diff`var' `var'
	}
	
	eststo `game': reg  decision  _same_eth  composite1  composite2  composite3  _same_sex  _same_age  $cyd_controls, cluster(ID)
	estadd local clust = "{" + string(e(N_clust)		,"%6.0fc") + "}" // The {} serve to avoid the scientific alignment
	estadd local obs   = "{" + string(e(N)/2			,"%6.0fc") + "}"
	estadd local dec   = "{" + string(e(N)/e(N_clust)/2	,"%6.0fc") + "}"
	sum cyd_same_eth_chosen if game == 2
}
else {	
	eststo `game': reg  share  1.treatment  1._same_eth  composite1  composite2  composite3  1._same_sex  1._same_age  $controls, cluster(ID)
	estadd local clust = "{" + string(e(N_clust)		,"%6.0fc") + "}" // The {} serve to avoid the scientific alignment
	estadd local obs   = "{" + string(e(N)				,"%6.0fc") + "}"
	estadd local dec   = "{" + string(e(N)/e(N_clust)	,"%6.0fc") + "}"
	if "`game'" == "social_proximity" sum decision
	else sum share
}
	estadd local mean = string(r(mean),"%9.`=$precision'f")
	estadd local sd = "(" + string(r(sd),"%9.`=$precision'f") + ")"

if "`game'" == "cyd" {
	#delimit ;
	n mhtreg 
	(decision  _same_eth  composite1  composite2  composite3  _same_sex  _same_age  $cyd_controls)
	(decision  composite1  _same_eth  composite2  composite3  _same_sex  _same_age  $cyd_controls)
	, cluster(ID) bootstrap($mht_bootstrap);
	#delimit cr
	
	mat `game' = r(results)
	pstar, b(`=`game'[1,2]') p(`=`game'[1,4]') precision($precision) pbracket
	estadd local diff_eth	  = r(bstar)
	estadd local diff_eth_SE  = r(pstar)

	pstar, b(`=`game'[2,2]') p(`=`game'[2,4]') precision($precision) pbracket
	estadd local eth_Delta   = r(bstar)
	estadd local eth_DeltaSE = r(pstar)
}
else {
	#delimit ;
	n mhtreg 
	(share  1.treatment  1._same_eth  composite1  composite2  composite3  1._same_sex  1._same_age  $controls)
	(share  1._same_eth  1.treatment  composite1  composite2  composite3  1._same_sex  1._same_age  $controls)
	(share  composite1  1.treatment  1._same_eth  composite2  composite3  1._same_sex  1._same_age  $controls)
	, cluster(ID) bootstrap($mht_bootstrap);
	#delimit cr

	mat `game' = r(results)
	pstar, b(`=`game'[1,2]') p(`=`game'[1,4]') precision($precision) pbracket
	estadd local pill	  = r(bstar)
	estadd local pill_SE  = r(pstar)
	
	pstar, b(`=`game'[2,2]') p(`=`game'[2,4]') precision($precision) pbracket
	estadd local diff_eth	  = r(bstar)
	estadd local diff_eth_SE  = r(pstar)

	pstar, b(`=`game'[3,2]') p(`=`game'[3,4]') precision($precision) pbracket
	estadd local eth_Delta   = r(bstar)
	estadd local eth_DeltaSE = r(pstar)
}
}

n esttab using "$tables_dir/spec1_mht.tex", $table_design drop(*) stats(mean sd pill pill_SE  diff_eth diff_eth_SE  eth_Delta eth_DeltaSE  clust dec obs, labels("Sample mean" "Sample standard deviation" "\midrule\multicolumn{4}{l}{\textit{Panel A: Average hydrocortisone effect$^a$}} \\ \quad Hydrocortisone effect" " " 	"\midrule \multicolumn{4}{l}{\textit{Panel B: Average coethnicity effect$^b$}} \\ \quad Coethnicity effect" " " "\midrule\multicolumn{4}{l}{\textit{Panel C: Interaction of hydrocortisone and coethnicity$^c$}} \\ \quad Interaction effect" " " "\midrule Participants" "Decisions per participant" "Decisions")) nonotes addnotes("\textit{Notes}: $^a$ The average hydrocortisone effect is calculated as in equation~\eqref{eqn: Calculated Hydro Effect}. $^b$ The average coethnicity effect is calculated as in equation~\eqref{eqn: Calculated Coethnity Effect}. $^c$ The interaction effect is given by $\hat{\beta}_3$ in equation~\eqref{eqn: Main Specification}. All terms are described in the text. In this specification, we control for the interaction of a same-gender and same-age group indicator with hydrocortisone as well as gender, age group and ethnicity fixed effects of both players. Standard errors clustered at the participant level. The $ p $-values are column-wise corrected for multiple hypothesis testing following \citet{list2019multiple} using `=string($mht_bootstrap, "%10.0fc")' bootstrap draws and are reported in brackets. Significance is denoted by \sym{*} \(p<0.1\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\).") mtitles("\specialcell{Choose Your \\ Dictator Game}" "\specialcell{Dictator \\ Game}" "\specialcell{Trust \\ Game 1}" "\specialcell{Trust \\ Game 2}" "\specialcell{Social \\ Proximity}" "\specialcell{Choose Your \\ Dictator Game}" "\specialcell{Dictator \\ Game}" "\specialcell{Trust \\ Game 1}" "\specialcell{Trust \\ Game 2}" "\specialcell{Social \\ Proximity}") substitute("{l}{\footnotesize" "{p{0.93\hsize-10pt}}{\footnotesize")
